<?php
class BidtestCommand extends CConsoleCommand{
    public $pid;
    public $runDate = 0;
    public $parame;
    
    public $startTime;
    
    public $argv;
    
    public function init(){
        $this->pid = getmypid();  
        $this->startTime = microtime();
    }
        
    public function runScript(){
        $fileName = 'log_'.$this->pid.'_'.time().'.test';
        $BidAuction = new BidAuction();
        $BidAuction->customerId = $this->argv[1];
        $BidAuction->auctionId  = $this->argv[2];
        $BidAuction->bid();
        $testArray = array(
            'PID'       => $this->pid,
            'START'     => $this->startTime,
            'END'       => microtime(),
            'RUN'       => (microtime() - $this->startTime),
            'CUSTOMER'  => $BidAuction->customerId,
            'AUCTION'   => $BidAuction->auctionId,
            'RETURN'    => json_encode($BidAuction->getResult()),
        );
        $text = implode(' | ', $testArray);
    
        file_put_contents("log/data.test",$text."\n",FILE_APPEND);
    }
    
    public function run($argv){
        $this->runDate = $argv[0];
        $this->argv = $argv;
        $loop = true;
        do{
            if (time() <= $this->runDate){
                continue;
            }else{
                $this->runScript();
                $loop = false;
            }
            sleep(1);
        }while($loop);
    }
}